/**create by framework at 2019年05月30日 15:47:03**/
package com.star.truffle.module.fzjz.controller.api;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.star.truffle.core.StarServiceException;
import com.star.truffle.core.annotation.IgnoreSecurity;
import com.star.truffle.core.eureka.StarGateway;
import com.star.truffle.core.web.ApiCode;
import com.star.truffle.core.web.ApiResult;
import com.star.truffle.module.fzjz.dto.req.WarInfoRequestDto;
import com.star.truffle.module.fzjz.dto.res.WarInfoResponseDto;
import com.star.truffle.module.fzjz.service.WarInfoService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import springfox.documentation.annotations.ApiIgnore;

@Slf4j
@RestController
@RequestMapping("/api/war")
@Api(tags = "WarInfoApiController")
public class WarInfoApiController {

  @Autowired
  private WarInfoService warInfoService;

  @IgnoreSecurity
  @StarGateway
  @RequestMapping(value = "/info", method = RequestMethod.POST)
  @ApiOperation(value = "根据主键获取作战图", notes = "根据主键获取作战图", httpMethod = "POST", response = WarInfoResponseDto.class)
  @ApiImplicitParams({
    @ApiImplicitParam(name = "id", value = "id", dataType = "Long", required = true, paramType = "query")
  })
  public ApiResult<WarInfoResponseDto> getWarInfo(Long id) {
    try {
      WarInfoResponseDto warInfoResponseDto = warInfoService.getWarInfo(id);
      return ApiResult.success(warInfoResponseDto);
    } catch (StarServiceException e) {
      return ApiResult.fail(e.getCode(), e.getMsg());
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      return ApiResult.fail(ApiCode.SYSTEM_ERROR);
    }
  }

  @IgnoreSecurity
  @StarGateway
  @RequestMapping(value = "/list", method = RequestMethod.POST)
  @ApiOperation(value = "根据条件获取作战图列表", notes = "根据条件获取作战图列表", httpMethod = "POST")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "id", value = "id", dataType = "Long", required = false, paramType = "query"),
    @ApiImplicitParam(name = "cateId", value = "分类", dataType = "Long", required = false, paramType = "query"),
    @ApiImplicitParam(name = "name", value = "事故名称", dataType = "String", required = false, paramType = "query"),
    @ApiImplicitParam(name = "occurrenceAddr", value = "事发地点", dataType = "String", required = false, paramType = "query"),
    @ApiImplicitParam(name = "incidentOrganization", value = "事发单位", dataType = "String", required = false, paramType = "query"),
    @ApiImplicitParam(name = "localeLeader", value = "现场负责人", dataType = "String", required = false, paramType = "query"),
    @ApiImplicitParam(name = "leaderMobile", value = "负责人电话", dataType = "String", required = false, paramType = "query"),
    @ApiImplicitParam(name = "accidentLevel", value = "事故级别", dataType = "String", required = false, paramType = "query"),
    @ApiImplicitParam(name = "accidentType", value = "事故类型", dataType = "String", required = false, paramType = "query"),
    @ApiImplicitParam(name = "page.pageNum", value = "页码，页码如果没有则查询满足条件的所有记录", dataType = "int", required = false, paramType = "query"),
    @ApiImplicitParam(name = "page.pageSize", value = "一页最大记录数，当页码有值时，该值没有指定则默认为10", dataType = "int", required = false, paramType = "query"),
    @ApiImplicitParam(name = "page.orderBy", value = "排序字段，必须和数据库的字段一致", dataType = "String", required = false, paramType = "query"),
    @ApiImplicitParam(name = "page.orderType", value = "升序/降序", dataType = "String", required = false, paramType = "query", allowableValues = "asc,desc")
  })
  public ApiResult<List<WarInfoResponseDto>> queryWarInfo(@ApiIgnore @RequestBody WarInfoRequestDto warInfoRequestDto) {
    try {
      List<WarInfoResponseDto> list = warInfoService.queryWarInfo(warInfoRequestDto);
      return ApiResult.success(list);
    } catch (StarServiceException e) {
      return ApiResult.fail(e.getCode(), e.getMsg());
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      return ApiResult.fail(ApiCode.SYSTEM_ERROR);
    }
  }
}